from django.shortcuts import render
from django.http import HttpResponse
import pyecharts
from .ana import DouBanAna_obj, r
import json

# Create your views here.

REMOTE_HOST = "https://pyecharts.github.io/assets/js"

def index(requst):

    return HttpResponse('OK')

def how_many_reviews_are_there_per_movie(request):

    bar = pyecharts.Bar('每个电影评论的次数')


    if r.exists('how_many_reviews_are_there_per_movie'):

        info_dict = json.loads(r.get('how_many_reviews_are_there_per_movie').decode())

        bar.add('test', list(info_dict.keys()), list(info_dict.values()))

    else:

        info = DouBanAna_obj.how_many_reviews_are_there_per_movie()

        bar.add('test', info.index, info.values)

    context = dict(
        
        myechart=bar.render_embed(),
        
        host=REMOTE_HOST,
        
        script_list=bar.get_js_dependencies()
        )

    print(bar.get_js_dependencies())

    return render(request, 'jishi/bootcss.html', context)

    

    
